home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tcl8.0 / mac / tclMacAppInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  5.2 KB  |  206 lines  |  [TEXT/CWIE]

  1. /* 
  2.  * tclMacAppInit.c --
  3.  *
  4.  *    Provides a version of the Tcl_AppInit procedure for the example shell.
  5.  *
  6.  * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
  7.  * Copyright (c) 1995-1997 Sun Microsystems, Inc.
  8.  *
  9.  * See the file "license.terms" for information on usage and redistribution
  10.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11.  *
  12.  * SCCS: @(#) tclMacAppInit.c 1.20 97/07/28 11:03:58
  13.  */
  14.  
  15. #include "tcl.h"
  16. #include "tclInt.h"
  17. #include "tclPort.h"
  18. #include "tclMac.h"
  19. #include "tclMacInt.h"
  20.  
  21. #if defined(THINK_C)
  22. #   include <console.h>
  23. #elif defined(__MWERKS__)
  24. #   include <SIOUX.h>
  25. short InstallConsole _ANSI_ARGS_((short fd));
  26. #endif
  27.  
  28. #ifdef TCL_TEST
  29. EXTERN int        TclObjTest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  30. EXTERN int        Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  31. #endif /* TCL_TEST */
  32.  
  33. /*
  34.  * Forward declarations for procedures defined later in this file:
  35.  */
  36.  
  37. static int        MacintoshInit _ANSI_ARGS_((void));
  38.  
  39. /*
  40.  *----------------------------------------------------------------------
  41.  *
  42.  * main --
  43.  *
  44.  *    Main program for tclsh.  This file can be used as a prototype
  45.  *    for other applications using the Tcl library.
  46.  *
  47.  * Results:
  48.  *    None. This procedure never returns (it exits the process when
  49.  *    it's done.
  50.  *
  51.  * Side effects:
  52.  *    This procedure initializes the Macintosh world and then 
  53.  *    calls Tcl_Main.  Tcl_Main will never return except to exit.
  54.  *
  55.  *----------------------------------------------------------------------
  56.  */
  57.  
  58. void
  59. main(
  60.     int argc,                /* Number of arguments. */
  61.     char **argv)            /* Array of argument strings. */
  62. {
  63.     char *newArgv[2];
  64.     
  65.     if (MacintoshInit()  != TCL_OK) {
  66.     Tcl_Exit(1);
  67.     }
  68.  
  69.     argc = 1;
  70.     newArgv[0] = "tclsh";
  71.     newArgv[1] = NULL;
  72.     Tcl_Main(argc, newArgv, Tcl_AppInit);
  73. }
  74.  
  75. /*
  76.  *----------------------------------------------------------------------
  77.  *
  78.  * Tcl_AppInit --
  79.  *
  80.  *    This procedure performs application-specific initialization.
  81.  *    Most applications, especially those that incorporate additional
  82.  *    packages, will have their own version of this procedure.
  83.  *
  84.  * Results:
  85.  *    Returns a standard Tcl completion code, and leaves an error
  86.  *    message in interp->result if an error occurs.
  87.  *
  88.  * Side effects:
  89.  *    Depends on the startup script.
  90.  *
  91.  *----------------------------------------------------------------------
  92.  */
  93.  
  94. int
  95. Tcl_AppInit(
  96.     Tcl_Interp *interp)        /* Interpreter for application. */
  97. {
  98.     if (Tcl_Init(interp) == TCL_ERROR) {
  99.     return TCL_ERROR;
  100.     }
  101.  
  102. #ifdef TCL_TEST
  103.     if (Tcltest_Init(interp) == TCL_ERROR) {
  104.     return TCL_ERROR;
  105.     }
  106.     Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init,
  107.             (Tcl_PackageInitProc *) NULL);
  108.     if (TclObjTest_Init(interp) == TCL_ERROR) {
  109.     return TCL_ERROR;
  110.     }
  111. #endif /* TCL_TEST */
  112.  
  113.     /*
  114.      * Call the init procedures for included packages.  Each call should
  115.      * look like this:
  116.      *
  117.      * if (Mod_Init(interp) == TCL_ERROR) {
  118.      *     return TCL_ERROR;
  119.      * }
  120.      *
  121.      * where "Mod" is the name of the module.
  122.      */
  123.  
  124.     /*
  125.      * Call Tcl_CreateCommand for application-specific commands, if
  126.      * they weren't already created by the init procedures called above.
  127.      * Each call would loo like this:
  128.      *
  129.      * Tcl_CreateCommand(interp, "tclName", CFuncCmd, NULL, NULL);
  130.      */
  131.  
  132.     /*
  133.      * Specify a user-specific startup script to invoke if the application
  134.      * is run interactively.  On the Mac we can specifiy either a TEXT resource
  135.      * which contains the script or the more UNIX like file location
  136.      * may also used.  (I highly recommend using the resource method.)
  137.      */
  138.  
  139.     Tcl_SetVar(interp, "tcl_rcRsrcName", "tclshrc", TCL_GLOBAL_ONLY);
  140.     /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
  141.  
  142.     return TCL_OK;
  143. }
  144.  
  145. /*
  146.  *----------------------------------------------------------------------
  147.  *
  148.  * MacintoshInit --
  149.  *
  150.  *    This procedure calls initalization routines to set up a simple
  151.  *    console on a Macintosh.  This is necessary as the Mac doesn't
  152.  *    have a stdout & stderr by default.
  153.  *
  154.  * Results:
  155.  *    Returns TCL_OK if everything went fine.  If it didn't the 
  156.  *    application should probably fail.
  157.  *
  158.  * Side effects:
  159.  *    Inits the appropiate console package.
  160.  *
  161.  *----------------------------------------------------------------------
  162.  */
  163.  
  164. static int
  165. MacintoshInit()
  166. {
  167. #if GENERATING68K && !GENERATINGCFM
  168.     SetApplLimit(GetApplLimit() - (TCL_MAC_68K_STACK_GROWTH));
  169. #endif
  170.     MaxApplZone();
  171.  
  172. #if defined(THINK_C)
  173.  
  174.     /* Set options for Think C console package */
  175.     /* The console package calls the Mac init calls */
  176.     console_options.pause_atexit = 0;
  177.     console_options.title = "\pTcl Interpreter";
  178.         
  179. #elif defined(__MWERKS__)
  180.  
  181.     /* Set options for CodeWarrior SIOUX package */
  182.     SIOUXSettings.autocloseonquit = true;
  183.     SIOUXSettings.showstatusline = true;
  184.     SIOUXSettings.asktosaveonclose = false;
  185.     InstallConsole(0);
  186.     SIOUXSetTitle("\pTcl Interpreter");
  187.         
  188. #elif defined(applec)
  189.  
  190.     /* Init packages used by MPW SIOW package */
  191.     InitGraf((Ptr)&qd.thePort);
  192.     InitFonts();
  193.     InitWindows();
  194.     InitMenus();
  195.     TEInit();
  196.     InitDialogs(nil);
  197.     InitCursor();
  198.         
  199. #endif
  200.  
  201.     Tcl_MacSetEventProc((Tcl_MacConvertEventPtr) SIOUXHandleOneEvent);
  202.     
  203.     /* No problems with initialization */
  204.     return TCL_OK;
  205. }
  206.